﻿<ToolTip x:Class="tomenglertde.ResXManager.View.Visuals.CodeReferencesToolTip"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
         xmlns:model="urn:ResXManager.Model"
         xmlns:system="clr-namespace:System;assembly=mscorlib"
         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
         xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
         xmlns:toms="urn:TomsToolbox"
         xmlns:properties="clr-namespace:tomenglertde.ResXManager.View.Properties"
         d:DataContext="{d:DesignInstance model:ResourceTableEntry}">
  <ToolTip.Template>
    <ControlTemplate TargetType="Control">
      <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
        <Grid Margin="{TemplateBinding Padding}">
          <Grid DataContext="{toms:Import model:CodeReferenceTracker}" d:DataContext="{d:DesignInstance model:CodeReferenceTracker}">
            <ProgressBar x:Name="Progress" Maximum="100" BorderThickness="0" Background="Transparent" Visibility="Collapsed"
                         Value="{Binding Path=Progress, Mode=OneWay}" />
            <TextBlock x:Name="Text" MaxWidth="300" TextWrapping="Wrap" />
          </Grid>
          <ItemsControl x:Name="ItemsControl" ItemsSource="{Binding CodeReferences}" Grid.IsSharedSizeScope="True">
            <ItemsControl.ItemTemplate>
              <DataTemplate DataType="{x:Type model:CodeReference}">
                <Grid>
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="FileName" />
                    <ColumnDefinition />
                  </Grid.ColumnDefinitions>
                  <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="1">
                    <TextBlock Text="{Binding ProjectFile.RelativeFilePath}" />
                    <TextBlock Text=" (" />
                    <TextBlock Text="{Binding LineNumber}" />
                    <TextBlock Text="): " />
                  </StackPanel>
                  <ItemsControl Grid.Column="1" ItemsSource="{Binding LineSegments}" AlternationCount="2" Foreground="Black" Background="White">
                    <ItemsControl.ItemsPanel>
                      <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" />
                      </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                      <DataTemplate DataType="system:String">
                        <TextBlock Text="{Binding}">
                          <TextBlock.Style>
                            <Style TargetType="TextBlock">
                              <Style.Triggers>
                                <DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(ItemsControl.AlternationIndex)}" Value="1">
                                  <Setter Property="FontWeight" Value="Bold" />
                                  <Setter Property="Foreground" Value="DarkOliveGreen" />
                                </DataTrigger>
                              </Style.Triggers>
                            </Style>
                          </TextBlock.Style>
                        </TextBlock>
                      </DataTemplate>
                    </ItemsControl.ItemTemplate>
                  </ItemsControl>
                </Grid>
              </DataTemplate>
            </ItemsControl.ItemTemplate>
          </ItemsControl>
        </Grid>
        <i:Interaction.Triggers>
          <ei:TimerTrigger MillisecondsPerTick="1000">
            <toms:UpdatePropertyAction TargetName="Text" Property="{x:Static TextBlock.TextProperty}" />
            <toms:UpdatePropertyAction TargetName="Progress" Property="{x:Static ProgressBar.ValueProperty}" />
          </ei:TimerTrigger>
        </i:Interaction.Triggers>
      </Border>
      <ControlTemplate.Triggers>
        <DataTrigger Binding="{Binding ElementName=ItemsControl, Path=Items.Count}" Value="0">
          <Setter TargetName="Text" Property="Text" Value="{x:Static properties:Resources.NoCodeReferencesToolTip}" />
        </DataTrigger>
        <DataTrigger Binding="{Binding CodeReferences}" Value="{x:Null}">
          <Setter TargetName="Text" Property="Text" Value="{Binding Path=Progress, Source={toms:Import model:CodeReferenceTracker}, StringFormat={x:Static properties:Resources.CodeReferenceTrackingInProgress}}"/>
          <Setter TargetName="Progress" Property="Visibility" Value="Visible" />
        </DataTrigger>
        <MultiDataTrigger>
          <MultiDataTrigger.Conditions>
            <Condition Binding="{Binding CodeReferences}" Value="{x:Null}" />
            <Condition Binding="{Binding Container.IsWinFormsDesignerResource}" Value="True" />
          </MultiDataTrigger.Conditions>
          <Setter TargetName="Text" Property="Text" Value="Code references for WinForms are not evaluated." />
        </MultiDataTrigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
  </ToolTip.Template>
</ToolTip>